﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BobcatUtility
{
    /// <summary>
    /// This control shows one icon that can be hosted as part of the IconStripControl. It shows
    /// an image with a label, and raises an event when it's clicked. When you call setIcon to
    /// set up the image, you provide an ID. This string will be passed to event handlers when the
    /// control is clicked to identify it.
    /// </summary>
    public partial class IconControl : UserControl
    {
        #region Events

        /// <summary>
        /// Data passed with events raise by this control.
        /// </summary>
        public class Args : EventArgs
        {
            public string ID { get; set; }
        }

        /// <summary>
        /// Event raised when the image shown by this control is clicked.
        /// </summary>
        public event EventHandler<Args> ClickedEvent;

        #endregion

        #region Public properties

        /// <summary>
        /// Read-only property to return the ID (set in setIcon).
        /// </summary>
        public string ID 
        {
            get { return m_strID; }
        }

        #endregion

        #region Public methods

        /// <summary>
        /// Constructor.
        /// </summary>
        public IconControl()
        {
            InitializeComponent();
        }

        /// <summary>
        /// You pass in the image, label and unique ID for this icon.
        /// </summary>
        public void setIcon(Image image, string strLabel, string strID)
        {
            ctrlImage.Image = image;
            label.Text = strLabel;
            m_strID = strID;
        }

        #endregion

        #region Private functions

        /// <summary>
        /// Called when the image is clicked. We raise our own click event.
        /// </summary>
        private void ctrlImage_Click(object sender, EventArgs e)
        {
            Utility.CrossThreadInvoke(ClickedEvent, this, new Args { ID = m_strID });
        }

        #endregion

        #region Private data

        private string m_strID = "";

        #endregion

    }
}
